/**
 * Created on 13 avr. 08 by Sebastian Audet
 */
package gui2Dengine;

import grid.GridOutOfBounds;
import grid.HexGrid;
import grid.Location;

import java.awt.Shape;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Sebastian Audet
 *
 */
public class HexDisplayMap extends DisplayMap {
    
    Map<Location,Hexagon> pointmap;
    
    HexDisplayMap(HexGrid grid,double length,double width)
    {
	super(grid, length, width);
	shapes = new ArrayList<Shape>();
	shapemap = new HashMap<Location,Shape>();
	pointmap = new HashMap<Location,Hexagon>();
    }

    /* (non-Javadoc)
     * @see gui2Dengine.DisplayMap#generateShapeData()
     */
    public void generateShapeData(int xoffset, int yoffset, int xunits, int yunits) {
	//Generate HexGrid shape data
	    Point2D.Double p = new Point2D.Double(0,new Double(Hexagon.getTriSideLength(length)).intValue());
	    boolean switcher;
	    if((yoffset%2)==0) {
		switcher = true;
	    } else {
		switcher = false;
	    }
	    for (int i = 0; i < yunits; i++) {
		for (int j = 0; j < xunits; j++) {
		    Point2D.Double point = null;
		    if (switcher) {
			point = new Point2D.Double(
				p.x
					+ j
					* (Hexagon.getBisectorDistance(length) + length),
				p.y + (i * Hexagon.getTriSideLength(length)));
		    } else {
			point = new Point2D.Double(
				p.x
					+ Hexagon.getRadiusDistance(length)
					+ (length / 2)
					+ j
					* (Hexagon.getBisectorDistance(length) + length),
				p.y + (i * Hexagon.getTriSideLength(length)));
		    }
		    Hexagon hex = new Hexagon(point, length);
		    Shape shape = hex.getHexagon();
			try {
			    pointmap.put(grid.getNode(new Location(j+yoffset, i+xoffset))
				    .getLocation(), hex);
			    shapemap.put(grid.getNode(new Location(j+yoffset, i+xoffset))
				    .getLocation(), shape);
			} catch (GridOutOfBounds e) {
			    e.printStackTrace();
			}
			shapes.add(shape);
		}
		switcher = !switcher;
	    } // End HexGrid Code
    }

}
